package com.ocm.core.mapping;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.googlecode.simpleobjectassembler.converter.AbstractObjectConverter;
import com.ocm.core.domain.UserDetailType;
import com.ocm.core.exception.OCMRuntimeException;
import com.ocm.core.exception.UnsupportTypeException;

@Component
public class IntegerToUserDetailTypeConvert extends AbstractObjectConverter<Integer, UserDetailType> {

   private static final Logger LOG = Logger.getLogger(IntegerToUserDetailTypeConvert.class);

   @Override
   public void convert(Integer sourceObject, UserDetailType destinationObject) {
      try {
         destinationObject = UserDetailType.getUserDetailType(sourceObject.intValue());
      }
      catch (UnsupportTypeException e) {
         LOG.error(e);
      }
   }

   @Override
   public UserDetailType createDestinationObject(Integer sourceObject) {
      try {
         return UserDetailType.getUserDetailType(sourceObject.intValue());
      }
      catch (UnsupportTypeException e) {
         LOG.error(e);
         throw new OCMRuntimeException(e.getMessage());
      }
   }
}
